package com.weblog.weblog.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author gc
 * @class_name Knife4jConfig
 * @date 2023年09月14日 19:37
 */

@Configuration
@EnableSwagger2WebMvc
@Profile("dev")
public class Knife4jConfig {

    @Bean("WebApi")
    public Docket createApiDoc(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo())
                //分组
                .groupName("Web 前端接口")
                .select()
                //指定扫描报路径
                .apis(RequestHandlerSelectors.basePackage("com.weblog.weblog.web.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /*
     * 构建Api信息
     * @author gc
     * @date 2023/9/14 19:44
     * @return springfox.documentation.service.ApiInfo
     */
    private ApiInfo buildApiInfo() {
        return new ApiInfoBuilder()
                .title("Weblog 前端接口文档")
                .description("Weblog ****") //描述
                .termsOfServiceUrl("https://********")  //API服务条款
                .contact(new Contact("gc","https://*********","gchong3068@outlook.com"))  //联系人
                .version("1.0") //版本号
                .build();

    }
}
